package com.own.component.util.math.util;

import lombok.extern.slf4j.Slf4j;

import javax.script.ScriptEngineManager;

/**
 * BooleanCalculateUtil
 *
 * @author chenxueli
 * @date 2022-06-15 03:14:15
 */
@Slf4j
public class BooleanCalculateUtil extends AbstractCalculateUtil<Boolean, String> {

    /**
     * 计算
     *
     * @param expression 表达式信息
     * @return 值信息
     * @author chenxueli
     * @date 2022-06-15 03:14:15
     */
    @Override
    public Boolean calculate(String expression) {
        var engine = new ScriptEngineManager().getEngineByName("JavaScript");
        try {
            return (Boolean) engine.eval(expression);
        } catch (Exception e) {
            return false;
        }
    }

}
